/*************************************************************************
	> File Name: block.c
	> Author: Angel Criss
	> Blog: blog.abbycin.tk 
	> Created Time: 2014年06月14日 星期六 20时53分34秒
 ************************************************************************/

// THIS PROGRAM ONLY BLOCK SIGTERM: 15

#include<unistd.h>
#include<stdio.h>
#include<signal.h>
int main(int argc, char *argv[])
{
    sigset_t jihe;
    // above code to initial a signal set ' jihe'
    int signum;
    signum=atoi(argv[2]);
    if(sigemptyset(&jihe)==-1)
    {
        perror("sigemptyset:");
        raise(2);
    }
    if(sigaddset(&jihe,15)==-1) // add SIGTERM to sig set namely: jihe
    {
        perror("sigaddset:");
        raise(2);
    }
    if(sigprocmask(SIG_SETMASK,&jihe,NULL)==-1) // set up block to SIGTERM
    {
        perror("block:");
        raise(2);
    }
    else
    {
        printf(" sig is being blocked by this code\n");
    }
    int i;
    for(i=0;i<20;i++)
        sleep(1);

    printf("\e[32m now test is the sig in that set?\e[0m\n\n\n");
    sleep(2);

    if(sigismember(&jihe,signum)==0) 
    {
        printf("\e[36m is not a member...\e[0m\n");
    }
    else
    {
        printf("\e[34m is the member, I added it by using sigaddset :) \e[0m\n\n\n");
    }
    _exit(0);
}
